﻿@using ETD.Common.Extension;
@using ETD.WebOrganization.Libs.Helper;
@using ETD.WinClient.Config;
@using ETD.Domain.EnumModels;
@using ETD.Domain.WebModels;
@using ETD.Common;
@using ETD.WebOrganization.Libs.Controls;
@model ETD.WebOrganization.Areas.Web.Models.ModelBase
<style>
    .weui-footer_fixed-bottom {
        position: relative !important;
    }
</style>
<div class="weui-msg">
    <div class="weui-msg__icon-area"><img src="@Url.MapMvcAssets("NormalImages/logo.png")" style="width:100px;height:100px;" /></div>
    <div class="weui-msg__text-area">
        <h2 class="weui-msg__title">@(Model.HeaderNav.Title)</h2>
    </div>
</div>
<form id="form" onsubmit="return false;">
    <input type="hidden" name="act" value="login">
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell ">
            <div class="weui-cell__hd"><label class="weui-label">帐号 <span style="color:red;">*</span></label></div>
            <div class="weui-cell__bd"><input class="weui-input" id="txtUsername" name="txtUsername" type="text" placeholder="请转入帐号名称" maxlength="20"></div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">密码 <span style="color:red;">*</span></label></div>
            <div class="weui-cell__bd"><input class="weui-input" type="password" id="txtPassword" name="txtPassword" maxlength="20" placeholder="请输入帐号的密码"></div>
        </div>

    </div>
    <div class="weui-msg__opr-area">
        <p class="weui-btn-area" id="login_btn">
            <a href="javascript:;" id="btnLogin" class="weui-btn weui-btn_primary">登 录</a>
        </p>
    </div>
</form>
<div class="weui-footer weui-footer_fixed-bottom">
    <p class="weui-footer__text">Copyright © 2019</p>
</div>

@section ScriptSection{
    <script>
        $(function () {

            $("#btnLogin").click(PageObj.onBtnLoginClick);
        });
        var PageObj = {};
        PageObj.onBtnLoginClick = function () {
            var checkFormResult = PageObj.checkForm();
            if (!checkFormResult) return;
            PageObj.login();
        }
        PageObj.checkForm = function () {
            var username = $("#txtUsername").val();
            if (StringHelper.isNullOrEmpty(username)) {
                $.toptip('请输入账号', 'warning');
                return false;
            }

            var password = $("#txtPassword").val();
            if (StringHelper.isNullOrEmpty(password)) {
                $.toptip('请输入密码', 'warning');
                return false;
            }

            return true;
        }
        PageObj.login = function () {
            var paras = {};
            paras.UserName = $("#txtUsername").val().trim();
            paras.Password = $("#txtPassword").val().trim();

            console.log(JSON.stringify(paras));

            ajaxPost("@Url.ActionTS("LoginFromWeb", "Account")", paras, function (data) {
                console.log(data);
                if (data.Status) {
                    $.toast(data.Info);
                    var modelData = data.Data;
                    window.setTimeout(function () {

                        if (modelData.PasswordChangeRequired) {
                            window.location.href = "@Url.ActionTS("ChangePassword", "SelfCenter")";
                        } else {
                            window.location.href = "@Url.ActionTS("Home", "Home")";
                        }

                    }, 2000);
                } else {
                    $.toast(data.Info, "forbidden");
                }
            });
        }
    </script>
}